\documentclass[a4paper,12pt]{report}

\usepackage{graphicx}                   % Grafikkh�dtering

\usepackage{amsmath}
\usepackage{amssymb}

\usepackage{listings}

\newcounter{num}
\setcounter{num}{1}


%---------------------------------
% new commands
%---------------------------------
\newcommand{\num}{\thenum \stepcounter{num}}
\newcommand{\tbf}{\textbf}

%\renewcommand{\labelenumi}{\alph{enumi})}

\begin{document}

\lstset{language=[LaTeX]TeX}


\chapter*{Python Exercises}

%\section*{\underline{}}
Some of these exercises are adapted from INF109 spring 2011. 

%------------------------------------------------------------------------------------------------------
\subsection*{EXERCISE \num}
    \begin{itemize}
        \item The Fibonacci sequence: $\{F\} = 0,1,1,2,3,5,8,13,21,35,\ldots$. Each term in the Fibonacci sequence is the sum of the two preceding terms, except for the first two terms which are \{0,1\}.
    \end{itemize}

	\begin{enumerate}
        \item Write a function, \texttt{fibonacci(n)} which returns the nth element of the Fibonacci sequence
            \begin{lstlisting}
                fibonacci(1) = 1
                fibonacci(2) = 1
                fibonacci(6) = 8
            \end{lstlisting}
        \item Write a recursive Fibonacci function
        \item Which method is better and why?
	\end{enumerate}

\subsection*{EXERCISE \num}
    Write a sorting function that will sort a given list. The program should accomplish the following:
    \begin{lstlisting}
     >>> a = [7,1,3,5,2,8]
     >>> my_sort(a)
     >>> print a
        [1,2,3,5,7,8]
    \end{lstlisting}
    Try using the function \texttt{enumerate}

\subsection*{EXERCISE \num}
    Write a python program that calculates the expected increase in population based on input from the user. The program should read (either as terminal input or argument input) (1) the current size of the population (integer), (2) growth rate in percent (float) and (3) number of years to predict (integer). 
For every year the program should print the predicted population rounded to the nearest integer. The program should also print the total growth in percent. 


    This is an example:

    \begin{lstlisting}
    >>> populationGrowth()
    Population: 1000
    Growth rate (pr. year in percent): 2.48
    Number of years: 5

    Population after 1 year is 1025.8
    Population after 2 years is 1050
    Population after 3 years is 1076
    Population after 4 years is 1103
    Population after 5 years is 1130
    Total growth after 5 years is (in percent) 13.03%
    >>>
    \end{lstlisting}

    Criteria for a good program:
    \begin{enumerate}
        \item The program does what it is supposed to.
        \item The program prints / returns useful information.
        \item The program handles common errors.
        \item The program is documented and well organised.
        \item Variable names are useful and understandable.
    \end{enumerate}

    

\subsection*{EXERCISE \num}
More exercises (in Norwegian) can be found at the home page for INF109, spring 2011. Follow INF109 at My Page. 

\end{document}

